home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / rddbase.arc / RDDBASE.INC < prev    next >
Encoding:
Text File  |  1986-01-29  |  7.2 KB  |  225 lines

  1.  
  2. (******************************************************************************
  3.  RDDBASE - Version 1.00 - 01/29/86
  4.  
  5.      Copyright(c) 1986,Third Wave Systems  , ALL RIGHTS RESERVED
  6.  
  7.       Written by K.R. Grenier for Public Domain use ONLY.
  8.  
  9.       A colletion of Turbo Pascal Routines to be
  10.       Used in reading and Updating DBASe III Files Outside of
  11.       The DBASE III programing Environment,
  12.  
  13.  
  14. NOTICE!!!!
  15.  
  16. RDDBASE may not be sold, used in a commerical environment, nor packaged with
  17. any commerical product without prior written permission from Third Wave
  18. Systems.  The routines may be freely distributed and / or included in compiled
  19. Turbo Pascal Programs for commercial purposes.
  20.  
  21. RDDBASE may be distributed freely at no cost to the recipient.  User support
  22. for this utility may be best obtained by notifying Third Wave Systems.
  23.  
  24. If you feel that this utility is of value, please feel free to send your
  25. voluntary contribution of $10.00.  This contribution will entitle you to
  26. notification of Future updates and user support.
  27.  
  28.        Make your Contribution check payable to
  29.  
  30.        Third Wave Systems
  31.        131 E 22nd Ave A
  32.        Box 124
  33.        Coal Valley, Il 61240
  34.  
  35.  
  36. DESCRIPTION:
  37.  
  38.   RDDBASE is a collection of TURBO Pascal 3.0 procedures that allow the
  39.   developer to write programs that read and update DBASE III database files
  40.   outside the DBASE III environment.
  41.  
  42.   The procedures included are:
  43.  
  44.       Open_Dbase_File - Used to open a DBASE III file and set up necessary
  45.                         parameters.
  46.  
  47.       Close_Dbase_File - Used to close a DBASE III file and reset necessary
  48.                          header information
  49.  
  50.       Read_Dbase_Record - Reads DBASE III Record either sequentially
  51.                           or randomly
  52.  
  53.       Read_Previous_Dbase_Record - Reads the DBASE III backwards from the
  54.                                    current record position
  55.  
  56.       Rewrite_Dbase_Record - Writes an uodated DBASE III record back to the
  57.                              database.
  58.  
  59. TIPS.
  60.  
  61.    Multiple DataBases can be processed within one program.  Be sure to
  62.    assign each a variable name  and a type of FILE.
  63.  
  64.    Limited global variables are used.  Those required by RDDBASE begin
  65.    with the prefix Db_ .
  66.  
  67.    At this time RDDBASE does not support the DBASE III indexing files.
  68.    The developer can create TURBO Pascl indices using The TURBO TOOLBOX
  69.    routines. These routines will build temporary indices rather quickly.
  70.    When using these routines
  71.       Create an index only
  72.       Establish the Relative record counter manually
  73.       The first record in the DBASE III file is Relative Record 1.
  74.  
  75.    To Delete DBASE III records set Byte one of the DBASE III record to
  76.    *.  Reorganize the database under the DBASE III environment using
  77.    the appropriate indices.
  78.  
  79.    End of File is not Handled properly in all cases and may cause the
  80.    program to terminate with an I/O if care is not taken.
  81.  
  82. FUTURE ENHANCEMENTS
  83.  
  84.    Fix to EOF Problem.
  85.  
  86.    Process DBASE III indices.
  87.  
  88.    Ability to ADD records to the DBASE III files.
  89.  
  90. Any suggestions or questions can be left on the
  91.  
  92.   COLLIER INTERNATIONAL BLUE BOARD
  93.      818-240-6006
  94.  
  95. DISCLAIMER
  96.  
  97. The author has taken due care in developing and testing the effectiveness of
  98. these routines, and makes no expressed or implied warranty of any kind.
  99. In no event shall the author or Third Wave Systems be liable for incidental
  100. or consequential damages in connection with or arising out of the use of
  101. these routines.
  102.  
  103.      NOTES
  104.      -----
  105.  
  106. DBASE III is a trademark of ASHTON-TATE.
  107. TURBO PASCAL is a trademark of BORLAND INTERNATIONAL.
  108. TURBO PASCAL TOOLBOX is a trademark of BORLAND INTERNATIONAL.
  109.  
  110. ************************************************************************)
  111.  
  112.  
  113. (*************** Required Variables and Constants  ****************)
  114. Type
  115. Db_File_Information_Block  = Record
  116.     Header_Size,
  117.     Record_Size   :Integer;
  118.     end;
  119.  
  120. Db_String80  =String[80];
  121.  
  122.  Var
  123.  Db_File_Information   :Array[1..30] of Db_File_Information_Block;
  124.  Db_Handle             :integer;
  125.  Db_Offset             :Real;
  126.  
  127. (*********************** Open A Dbase File ******************************)
  128.  
  129. Procedure Open_Dbase_File(Var Dbase_File :File;
  130.                               FileName :Db_String80);
  131.  
  132.  
  133. Begin
  134. Assign(DBase_File,FileName);
  135. Reset(Dbase_File,1);
  136. Move(Dbase_File,Db_Handle,2);
  137. Longseek(Dbase_File,8);
  138. BlockRead(Dbase_File,Db_File_Information[Db_Handle],4);
  139. Db_Offset:= 1.0 * Db_File_Information[Db_Handle].Header_Size;
  140. LongSeek(Dbase_File,Db_Offset);
  141. end; {of Open Dbase File }
  142.  
  143. (********************** Close A Dbase File ***************************)
  144.  
  145. Procedure Close_Dbase_File(Var Dbase_File :File);
  146.  
  147. Begin
  148. Move(Dbase_File,Db_Handle,2);
  149. Longseek(Dbase_File,8);
  150. BlockWrite(Dbase_File,Db_File_Information[Db_Handle],4);
  151. Db_File_Information[Db_Handle].Header_Size:=0;
  152. Db_File_Information[Db_Handle].Record_Size:=0;
  153. Close(Dbase_File);
  154. end;   {of Close Dbase File}
  155.  
  156. (******************** Read Dbase Record ***************************)
  157.  
  158. Procedure Read_Dbase_Record(Var Dbase_File    :File;
  159.                                 Relative_Key  :Real;
  160.                             Var Dbase_Buffer);
  161.  
  162. {  Relative Key  = 0 will Read Next Record
  163.    Relative Key  > 0 will Read Record At Given Relative_Key Position }
  164.  
  165.  
  166. Begin
  167. Move(Dbase_File,Db_Handle,2);
  168. With Db_File_Information[Db_Handle]  do
  169. Begin
  170.    If Relative_Key <> 0 then
  171.       Begin
  172.       Db_Offset:= (Abs(Relative_Key) - 1) * Record_Size + Header_Size;
  173.       Longseek(Dbase_File,Db_OffSet);
  174.        end;  {Of If}
  175.    BlockRead(Dbase_File,Dbase_Buffer,Record_Size);
  176.    end; {Of With}
  177. end;  {of Read Dbase Record}
  178.  
  179. (******************** Read Previous Dbase Record ***************************)
  180.  
  181. Procedure Read_Previous_Dbase_Record(Var Dbase_File    :File;
  182.                                          Relative_Key  :Real;
  183.                                      Var Dbase_Buffer);
  184.  
  185. {  Relative Key  = 0 will ReRead Current Record Read
  186.    Relative Key  > 0 will Backup and Read The record at - relative key position}
  187.  
  188.  
  189.  
  190. Begin
  191. Move(Dbase_File,Db_Handle,2);
  192. With Db_File_Information[Db_Handle]  do
  193. Begin
  194.    Db_Offset:=LongFilePos(Dbase_File);
  195.    Db_Offset:=Db_Offset - (Abs(Relative_Key) + 1.0) * Record_Size;
  196.    If Db_Offset < 1.0 * Header_Size then
  197.       Db_Offset := 1.0 * Header_Size;
  198.    Longseek(Dbase_File,Db_OffSet);
  199.    BlockRead(Dbase_File,Dbase_Buffer,Record_Size);
  200.    end;  {Of With}
  201. end;  {of Read Previous Dbase Record}
  202.  
  203. (******************** ReWrite Dbase Record ***************************)
  204.  
  205. Procedure Rewrite_Dbase_Record(Var Dbase_File    :File;
  206.                                    Relative_Key  :Real;
  207.                                Var Dbase_Buffer);
  208.  
  209. {  Relative Key  not Used  }
  210.  
  211. Begin
  212. Move(Dbase_File,Db_Handle,2);
  213. With Db_File_Information[Db_Handle]  do
  214. Begin
  215.    Db_Offset:=LongFilePos(Dbase_File);
  216.    Db_Offset:=Db_Offset - 1.0 * Record_Size;
  217.    If Db_Offset < 1.0 * Header_Size then
  218.       Db_Offset := 1.0 * Header_Size;
  219.    Longseek(Dbase_File,Db_OffSet);
  220.    BlockWrite(Dbase_File,Dbase_Buffer,Record_Size);
  221.    end;  {Of With}
  222. end;  {of Rewrite Dbase Record}
  223.  
  224. (********************* End of Routines *************************************)
  225.